package com.guomao.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;

@Repository
//@Controller
public class BookDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    /**
     * @param id 图书主键
     * @return 图书价格
     */
    public int getPrice(String id) {
        String sql = "select price from book where  bookid = ?";
        Integer price = jdbcTemplate.queryForObject(sql, Integer.class, id);
        return price;
    }

    public void updateBalance(String name, int price) {
        String sql = "update account set balance = balance - ? where username = ?";
        jdbcTemplate.update(sql, price, name);
    }


    public void updateStock(String id) {
        String sql = "update bookstock set stock = stock - 1 where bookid = ?";
        jdbcTemplate.update(sql, id);
    }
}
